package graduate.wangyaqi.SeveralQuestions;

import graduate.wangyaqi.OnlyQuestions.OnlyQuestions;
import graduate.wangyaqi.ProgrammeQuestions.ProgrammeQuestions;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class SeveralQuestionsService {
    @Resource
    private SeveralQuestionsRepository severalQuestionsRepository;

    //保存数据
    @Transactional
    public void save(SeveralQuestions severalQuestion) {
        severalQuestionsRepository.save(severalQuestion);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        severalQuestionsRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<SeveralQuestions> getAll() {
        Iterable<SeveralQuestions> severalQuestions = severalQuestionsRepository.findAll();
        return severalQuestions;
    }

    @Transactional
    public Iterable<SeveralQuestions> getAllByTaotiID(int id){
        Iterable<SeveralQuestions> list = severalQuestionsRepository.findAllByTaotiID(id);
        return list;
    }
    @Transactional
    public Optional<SeveralQuestions> findById(Long aLong){
        return severalQuestionsRepository.findById(aLong);
    };

    @Transactional
    public int countAllByStuIDadnAndTaotiID(Long taotaoId ){
        return severalQuestionsRepository.countAllByTaotiID(taotaoId);
    }

    @Transactional
    public SeveralQuestions getFirstByTaotiIDAndIdIsGreaterThan(long taotiId, long id){
        return severalQuestionsRepository.getFirstByTaotiIDAndIdGreaterThan(taotiId,id);
    }

    @Transactional
    public SeveralQuestions getFirstByTaotiIDAndIdIsLessThan(long taotiId, long id){
        return severalQuestionsRepository.getFirstByTaotiIDAndIdLessThanOrderByIdDesc(taotiId,id);
    }
}
